<?php

require_once 'MainPageWidget.php';
class LastDocsWidget extends MainPageWidget
{
	var $title = 'Свежие новости';
	var $tdis = array();
	var $doctypes = array('doc'); // fixes #558
	var $docscount = 5;

	public function Render()
	{
		$community_oid = $this->acl_assistant->acl_data['comity_oid'];
		
		$tdis = array();
		foreach ( $this->tdis as $tdi ) {
			$tdis[$tdi+0] = $tdi+0;
		}

		$this->model = $this->getFeedModel();
		$this->model->rh = $this->ctx->rh;
		$this->model->setModelParams('tdis', $tdis);
		$this->model->setModelParams('filter_by_doctype', $this->doctypes);
		$this->model->setModelParams('page_number', 1);
		$this->model->setModelParams('page_citems', $this->docscount);
		$this->model->setModelParams('community_oid', $community_oid);

		$this->model->doStuff();

		$this->items = $this->model->getItems();

		return $this;
	}

	public function getFeedModel() {
		$this->ctx->rh->UseClass("AggregatedModel_Feed_FeedInterface");
		$this->ctx->rh->UseClass("AggregatedModel_Feed_ReaderItems");

		return new AggregatedModel_Feed_ReaderItems();
	}

	public function settingsForm ($config)
	{
		$tdis_list = $this->getTdis();

		$config['form'] = array(
			'title' => 'Настройка меню',
			'fields' => array(

				'title' => array(
					'type' => 'text',
					'title' => 'Название',
					'default' => $this->title,
					'description' => 'Название меню',
				),

				'docscount' => array(
					'type' => 'text',
					'title' => 'Количество записей',
					'default' => $this->docscount,
					'description' => 'Количество записей в ленте',
				),

				'tdis' => array(
					'type' => 'checklist',
					'title' => 'Список разделов',
					'description' => 'Разделы сообщества',
					'fields' => $tdis_list,
				),
			),
		);

		return $config['form'];
	}

}

